<template>
    <el-dialog title="指派司机" :visible="visible" append-to-body :destroy-on-close="true" @close="close">
        <el-form size="small" :model="ruleForm" ref="ruleForm">
            <el-form-item label="选择地址" prop="supply_address_id">
                <el-select v-model="ruleForm.supply_address_id" placeholder="请选择地址">
                    <el-option v-for="item in address" :key="item.supply_address_id" :label="item.address_detail" :value="item.supply_address_id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="选择司机" prop="driver_id">
                <el-select v-model="ruleForm.driver_id" placeholder="请选择司机">
                    <el-option v-for="item in driver" :key="item.driver_id" :label="item.contact" :value="item.driver_id">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" class="btn" size="small" @click="toAssign" :disabled="isDisabled" :loading="isLoading">提 交</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { addrList } from '../../../api/setting';
import { driverData } from '../../../api/driver';
import { orderDelivery } from '../../../api/order';
export default {
    name: 'AssignDriver',
    props: {
        checkType: {
            type: String,
            default: 'check'// check -- 多选  radio 单选
        }
    },
    data() {
        return {
            visible: false,
            isDisabled: false,
            isLoading: false,
            address: [],
            driver: [],
            ruleForm: {
                supply_order_id: "",
                driver_id: "",
                supply_address_id: "",
            },
        }
    },
    created() {
        this.getAddressList();
        this.getDriverList()
    },
    methods: {
        show() {
            this.visible = true;
        },
        getAddressList() {
            addrList().then(res => {
                if (res.code == 0) {
                    this.address = res.data;
                }
            })
        },
        getDriverList() {
            driverData().then(res => {
                if (res.code == 0) {
                    this.driver = res.data;
                }
            })
        },
        async toAssign() {
            this.isDisabled = true;
            this.isLoading = true;
            let res = await this.$getCsrToken();
            orderDelivery(this.ruleForm).then((res) => {
                if (res.code == 0) {
                    this.$message({
                        message: res.msg,
                        type: "success",
                    });
                    this.isDisabled = false;
                    this.isLoading = false;
                    this.$emit('reload')
                    this.close()
                } else {
                    this.isDisabled = false;
                    this.isLoading = false;
                }
            });
        },
        close() {
            this.visible = false;
        }
    }
}
</script>
<style scoped>
</style>